package cn.hinglo.baseservice.interceptors;

import cn.hinglo.baseservice.annotation.IgnoreToken;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.annotation.Annotation;
import java.util.Map;


/**
 * @author HingLo
 * @createTime: 2018/11/16 12:53
 * @description: 登录拦截器基类, 所有登录拦截的拦截器实现都必须继承此类
 */
public abstract class BaseLoginInterceptor extends BaseInterceptor {

    /**
     * 排除拥有的指定的注解的方法
     *
     * @return 是否忽略
     */
    @Override
    public Class<? extends Annotation> ignoreAnnotation() {
        return IgnoreToken.class;
    }

    /**
     * 具体登录拦截实现
     *
     * @param request       请求对象
     * @param response      响应流对象
     * @param handler       Object对象
     * @param handlerMethod handlerMethod 对象
     * @return 返回拦截结果
     * @throws Exception exception
     */
    @Override
    public abstract boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler, HandlerMethod handlerMethod)
            throws Exception;

    /**
     * 拦截成功后,需要将部分信息设置到request中,用于在业务层中使用该数据,例如用户ID 等
     *
     * @param msg      传入的信息
     * @param response response
     * @param request  请求对象
     */
    public abstract void success(HttpServletRequest request, HttpServletResponse response, Map<String, Object> msg);
}
